package fat.euro;

import org.apache.cordova.DroidGap;

import android.app.PendingIntent;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

public class FEuro2012Activity extends DroidGap {
	
	public final static String AUTH = "authentication";
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setIntegerProperty("loadUrlTimeoutValue", 60000);
        super.loadUrl("file:///android_asset/www/home.html");
        
        Thread t=new Thread(new Runnable() {
			public void run() {
				// TODO Auto-generated method stub
				register();
		        //showRegistrationId();
			}
        });
        t.start();
    }

    public void register() {
		Log.w("C2DM", "start registration process");
		Intent intent = new Intent("com.google.android.c2dm.intent.REGISTER");
		intent.putExtra("app",PendingIntent.getBroadcast(this, 0, new Intent(), 0));
		// Use registered Google email
		intent.putExtra("sender", "scrumlab@fpt.aptech.ac.vn");
		startService(intent);
	}

	public void showRegistrationId() {
		SharedPreferences prefs = PreferenceManager
				.getDefaultSharedPreferences(this);
		String string = prefs.getString(AUTH, "n/a");
		//Toast.makeText(this, string, Toast.LENGTH_LONG).show();
		Log.d("C2DM RegId", string);
	}
}
